package com.songzhili.nohttpdemo.activity;

import android.widget.TextView;

import com.songzhili.nohttpdemo.R;
import com.songzhili.nohttpdemo.api.Constants;
import com.songzhili.nohttpdemo.api.JavaBeanRequest;
import com.songzhili.nohttpdemo.base.BaseActivity;
import com.songzhili.nohttpdemo.bean.YanZhenjie;
import com.songzhili.nohttpdemo.api.HttpResponseCallBackListener;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.Request;
import com.yanzhenjie.nohttp.rest.Response;

public class MainActivity extends BaseActivity {

    private TextView show;

    @Override
    public int getContentView() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        show = (TextView) findViewById(R.id.show);
        Request<YanZhenjie> request = new JavaBeanRequest<>(Constants.URL_NOHTTP_JSONOBJECT, RequestMethod.POST, YanZhenjie.class);
        request.add("name", "yanzhenjie");
        request.add("pwd", 123);
        request(0, request, zhenjieHttpListener, true, true);
    }
    /**
     * 接受JavaBean响应。
     */
    private HttpResponseCallBackListener<YanZhenjie> zhenjieHttpListener = new HttpResponseCallBackListener<YanZhenjie>() {
        @Override
        public void onSucceed(int what, Response<YanZhenjie> response,YanZhenjie yanZhenjie) {
            show.setText(yanZhenjie.getData().getBlog());
        }

//        @Override
//        public void onFailed(int what, Response response) {
//
//        }
    };
    @Override
    public void initData() {

    }
}
